package com.example.demo.controller;


import com.example.demo.entity.Student;
import com.example.demo.entity.Table;
import com.example.demo.entity.useri;
import com.example.demo.mapper.UserDao;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {

    @Autowired
    UserDao userDao;

    @RequestMapping("/index")
    public  String getIndex(){
        System.out.println("进入这个方法了");
        return "index";
    }


    @RequestMapping("/user")
    public  String getuser(){
        System.out.println("进入这个方法了");
        return "user";
    }

    @RequestMapping("/product")
    public  String getproduct(){
        System.out.println("进入这个方法了");
        return "product";
    }






    @RequestMapping("/login")
    public  String getLogin(Model model){
//        List<useri> allUser = userDao.getAllUser();
//        model.addAttribute("usera",allUser);
        return "login";
    }

    @ResponseBody
    @RequestMapping("/deleteUser/{id}")
    public  String deleteUser(@PathVariable("id") int id){
        userDao.deleteUserById(id);

        return "删除成功";
    }


    @ResponseBody
    @RequestMapping("/getAllUer")
    public Table<useri> getAllUser(){
        List<useri> allUser = userDao.getAllUser();
        Table<useri>  tab= new Table<useri>();
        tab.setCount(allUser.size());
        tab.setData(allUser);
        return tab;
    }

    @ResponseBody
    @RequestMapping("/delUseriById")
    public int delUserIById(@RequestParam("id") int id){
        int i = userDao.deleteUserById(id);
        return i;
    }


}
